#include <stdio.h>
#include <stdlib.h> /*needed for exit()*/

FILE *getOpen();    /*function prototype*/
void inOut(FILE *); /*function prototype*/

int main()
{
    FILE *outFile;

    outFile = getOpen(); /*call the function*/
    inOut(outFile);      /*call the function*/

    fclose(outFile);
    printf("\nThe file has been successfully written.\n");

    return 0;
}

FILE *getOpen() /*getOpen() returns a pointer to a FILE*/
{
    FILE *fname;
    char name[13];

    printf("\nEnter a file name: ");
    gets(name);
    fname = fopen(name, "w");
    if (fname == NULL)
    {
        printf("\nFailed to open the file %s.\n", name);
        exit(1);
    }

    return (fname);
}

void inOut(FILE *fname) /*fname is a pointer to a FILE*/
{
    int count;
    char line[81]; /*enough storage for one line of text*/

    printf("Please enter five lines of text:\n");
    for (count = 0; count < 5; count++)
    {
        gets(line);
        fprintf(fname, "%s\n", line);
    }
}